//
//  LGHelpDetailArticleController.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/5/23.
//  文章

#import "LGHelpDetailArticleController.h"

@interface LGHelpDetailArticleController ()
/**   */
@property (nonatomic , strong)UIScrollView *scrollView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *contentLabel;

@end

@implementation LGHelpDetailArticleController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"问题详情";
    [self.view addSubview:self.scrollView];
    [self.scrollView addSubview:self.titleLabel];
    [self.view addSubview:self.contentLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.scrollView).offset(viewPix(20));
        make.left.equalTo(self.view).offset(viewPix(16));
        make.right.equalTo(self.view).offset(-viewPix(16));
    }];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(viewPix(15));
        make.left.right.equalTo(self.titleLabel);
    }];
    [self requestData];
}

-(void)requestData{
    [RequestUtil withPOST:@"/doctor/help/helpdetail" parameters:@{@"help_id":self.helpId} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        if(code == 200){
            NSString *content = LGNSString(returnData[@"content"]);
            self.titleLabel.text = LGNSString(returnData[@"title"]);

            NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithData:[content dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType} documentAttributes:nil error:nil];
            [attrStr addAttributes:@{NSFontAttributeName:LGFont(14)} range:NSMakeRange(0, attrStr.length)];
            self.contentLabel.attributedText = attrStr;
            CGFloat height = [content textHeightWithFont:LGFont(14) maxWidth:Screen_W-viewPix(32)];
            self.scrollView.contentSize = CGSizeMake(Screen_W, height+viewPix(70));
        }
    } error:^(NSError *error) {
        
    }];
}

-(UIScrollView *)scrollView{
    if(!_scrollView){
        _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, Screen_W, Screen_H-topBarHeight)];
        _scrollView.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
        _scrollView.showsVerticalScrollIndicator = NO;
    }
    return _scrollView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:2];
    }
    return _titleLabel;
}

-(UILabel *)contentLabel{
    if(!_contentLabel){
        _contentLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _contentLabel;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
